//
//Copyright GX. Yuan
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//   http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

/**
 * @file net.go
 * @brief Leetcode 剑指Offer 第二版
 * @details 剑指 Offer 26. 树的子结构
 * @author GX. Yuan  any question please send mail to yuanguanxu@qq.com
 * @date 2021-6-28
 * @version V1.0
 * @attention 硬件平台: windows 10 家庭版
 * SDK版本：Go 1.16.5
 * IDE版本：GoLand 2020.2.3
 */
package main

type TreeNode struct {
	Val   int
	Left  *TreeNode
	Right *TreeNode
}

func isSubStructure(A *TreeNode, B *TreeNode) bool {
	// 遍历到A 的位置没有找到对应的根值
	// 或者B的值，为空
	if A ==nil || B == nil {
		return false
	}
	if A.Val == B.Val { // 如果根节点相同，判断是否是子树
		if true==isright(A,B){
			return true
		}
	}
	// 只要有一个，找到子树，返回即可;
	return  isSubStructure(A.Right, B)  ||isSubStructure(A.Left, B)
}
// 判断是否是子树
func isright(A *TreeNode, B *TreeNode) bool {
	if B==nil {
		return true
	}
	if A==nil || A.Val != B.Val{
		return false
	}
	return  isright(A.Right, B.Right) && isright(A.Left, B.Left)
}

func main() {


}
// 思路: 先用遍历：找到对应的值
// 然后，使用递归，遍历，满足实现的要求